import { _decorator, Component, Node } from 'cc';
import { Battle } from '../../Battle';
import { MainTowerController } from '../Tower/MainTowerController';
import { EnemyFrameController } from './EnemyFrameController';
const { ccclass, property } = _decorator;

@ccclass('EnemyAttackTowerController')
export class EnemyAttackTowerController extends Component {

    @property(Number)
    private attackHp: number = 10;
    @property(Number)
    private attackInterval: number = 1;

    //是否在攻击
    private _isAttacking: boolean = false;
    // private _enemyFrameController: EnemyFrameController = null;

    onLoad() {
        // this._enemyFrameController = this.node.getChildByName("body").getComponent(EnemyFrameController);
    }

    AttackTower(speed, path, name, min, max) {
        if (!this._isAttacking) {
            this.schedule(this.OnAttack.bind(this), this.attackInterval);
            // this._enemyFrameController.UpdateAnimInfo(speed, path, name, min, max);
            this._isAttacking = true;
        }
    }
    
    EndAttack() {
        this._isAttacking = false;
        this.unscheduleAllCallbacks();
    }

    OnAttack() {
        let mainTower: MainTowerController = Battle.MainTowerNode.getComponent(MainTowerController);
        mainTower.UpdateMainTowerHpProgress(this.attackHp);
    }

}


